import {regionData, CodeToText, TextToCode} from 'element-china-area-data'

// 根据locationId获取地名信息
export function getlocation(ororganizations) {
  // 非递归写法
  let location = ''
  regionData.forEach(i1 => {
    if(i1.value == ororganizations.locationId) {
      location = i1.label
    } else if(i1.hasOwnProperty('children')) {
      i1.children.forEach(i2 => {
        // 如果是直辖市、港澳地区，会在这里return
        if(i2.value == ororganizations.locationId) {
          location = i1.label + i2.label
        } else if(i2.hasOwnProperty('children')) {
          // 如果不是是直辖市、港澳地区，会在这里return
          i2.children.forEach(i3 => {
            // console.log('有没有',JSON.stringify(i3))
            if (i3.value == ororganizations.locationId) {
              location = i2.label + i3.label
            }
          })
        }
      })
    }
  })
  return location
}

// 根据地区名获取locationId
export function  getLocationId(location) {
  // return TextToCode[location]
  let locationId = ''
  regionData.forEach(i1 => {
    if(i1.label == location) {
      locationId = i1.value
    } else if(i1.hasOwnProperty('children')) {
      i1.children.forEach(i2 => {
        if(i2.label == location) {
          locationId = i2.value
        } else if(i2.hasOwnProperty('children')) {
          i2.children.forEach(i3 => {
            if (i3.label == location) {
              locationId = i3.value
            }
          })
        }
      })
    }
  })
  return locationId
}

// 地名补全
export function getTheWholeLocationName(location) {
  switch (location) {
    case '黔东南':
      return '黔东南苗族侗族自治州'
      break;
    case '黔南':
      return '黔南布依族苗族自治州'
      break;
    case '黔西南':
      return '黔西南布依族苗族自治州'
      break;
    default:
      return location + '市'
  }
}
